/**
 * Copyright @ 2000 ysten Co. Ltd. 
 * All right reserved.     
 * @author: wangmin
 * date: 2016-07-11     
 */
package com.task.service.impl;

import com.task.bean.Constants;
import com.task.entity.Message;
import com.task.entity.ParentTask;
import com.task.repository.IMessageRepository;
import com.task.service.IMessageService;
import com.task.utils.PageUtil;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

/**
 * 消息服务
 */
@Service
public class MessageServiceImpl implements IMessageService {

    @Autowired
    IMessageRepository messageRepository;

    @Override
    public Page<Message> findMsgPage(Map<String, Object> searchParams, int pageNum, int rows)
    {
        PageRequest pageRequest = PageUtil.buildPageRequest(pageNum, rows, Constants.DESC, Constants.ID);
        Specification<Message> spec = PageUtil.buildSpecification(searchParams, Message.class);
        return messageRepository.findAll(spec, pageRequest);
    }

    @Override
    public Message findById(Long id) {
        return messageRepository.findOne(id);
    }

    @Override
    public void save(Message message) {
        messageRepository.save(message);
    }

    @Override
    public void delete(Long id) {
        messageRepository.delete(id);
    }
}
